package com.security.antitheft.ui;

import android.content.Context;
import android.content.SharedPreferences;

public class ShareUISetting {

	private static String PREF_PIN = "pin";
	private static String PREF_APPFLAG = "app_flag";
	public static final int JUST_INSTALLED = 1;
	public static final int OPT_CHANGED = 2;
	public static final int OPT_APPLY = 4;
	
	private static String PREF_EN_REMOTE_LOCATION = "enable_remote_location";
	private static String PREF_EN_REMOTE_LOCK = "enable_remote_lock";
	private static String PREF_EN_REMOTE_ERASE = "enable_remote_erase";
	private static String PREF_EN_PINS = "enable_pins";
	
	//k-review
	private static String VISIBLE_STATE_REMOTE_LOCATION = "visible_remote_location";
	private static String VISIBLE_STATE_REMOTE_LOCK = "visible_remote_lock";
	private static String VISIBLE_STATE_REMOTE_ERASE = "visible_remote_erase";
	private static String VISIBLE_STATE_PINS = "visible_pins";
	private static String RANDOM_PASSWORD = "random_password";
	
	private static String PREF_NAME = "securitycollector";
	
	public static int appFlag(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getInt(PREF_APPFLAG, JUST_INSTALLED);
	}
	
	public static void setAppFlag(Context c, int f) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putInt(PREF_APPFLAG, f);
		editor.commit();
	}
	
	public static String pins(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getString(PREF_PIN, "");
	}
	
	public static void setPin(Context c, String pwd, boolean enablePins) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString(PREF_PIN, pwd);
		//k-review
		editor.putBoolean(PREF_EN_PINS, enablePins);
		editor.commit();
	}
		
	public static boolean isEnableRemoteLocation(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_REMOTE_LOCATION, true);
	}

	public static boolean isEnableRemoteLock(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_REMOTE_LOCK, true);
	}
	
	public static boolean isEnableRemoteErase(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_REMOTE_ERASE, true);
	}
	
	public static boolean isEnablePins(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_PINS, false);
	}
	
	//k-review
	//control location, lock, erase, pins from remote
	public static boolean GetVSRemoteLocation(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(VISIBLE_STATE_REMOTE_LOCATION, true);
	}
	
	//control lock from remote
	public static boolean GetVSRemoteLock(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(VISIBLE_STATE_REMOTE_LOCK, false);
	}
	
	//control erase from remote
	public static boolean GetVSRemoteErase(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(VISIBLE_STATE_REMOTE_ERASE, false);
	}
	
	//control pins from remote
	public static boolean GetVSRemotePins(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(VISIBLE_STATE_PINS, true);
	}
	
	//random password
	public static String GetRandomPassword(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getString(RANDOM_PASSWORD, null);
	}
	
	public static void SetRandomPassword(Context c, String strPassword) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString(RANDOM_PASSWORD, strPassword);
		editor.commit();
	}

	public static void SetVisibleStateFromRemote(Context c, boolean visibleLocation, boolean visibleLock,
													boolean visibleErase, boolean visiblePins) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(VISIBLE_STATE_REMOTE_LOCATION, visibleLocation);
		editor.putBoolean(VISIBLE_STATE_REMOTE_LOCK, visibleLock);
		editor.putBoolean(VISIBLE_STATE_REMOTE_ERASE, visibleErase);
		editor.putBoolean(VISIBLE_STATE_PINS, visiblePins);
		editor.commit();
	}
	
	public static void saveSettings(Context c, boolean enableLocation, boolean enableLock, boolean enableErase, boolean enablePins, String pins) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(PREF_EN_REMOTE_LOCATION, enableLocation);
		editor.putBoolean(PREF_EN_REMOTE_LOCK, enableLock);
		editor.putBoolean(PREF_EN_REMOTE_ERASE, enableErase);
		editor.putBoolean(PREF_EN_PINS, enablePins);
		editor.putString(PREF_PIN, enablePins ? pins:"");
		editor.commit();
	}
	
}
